package com.zygh.policeasset.controller;

import com.alibaba.fastjson.JSONObject;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.DailyAsset;
import com.zygh.policeasset.service.DailyAssetsService;
import com.zygh.policeasset.service.DailyProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/dailyAsset"})
@Api(tags = {"日常资产管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/DailyAssettController.class */
public class DailyAssettController {
    @Autowired
    DailyAssetsService dailyAssetsService;
    @Autowired
    DailyProjectService dailyProjectService;

    @RequestMapping(value = {"/findbyid"}, method = {RequestMethod.GET})
    @ApiOperation("根据ID查询")
    public Object selectOne(Integer id) {
        DailyAsset dailyAsset = this.dailyAssetsService.findAllByid(id);
        if (StringUtils.isEmpty(dailyAsset)) {
            return new CommonResult().validateFailed("查询失败");
        }
        return new CommonResult().success(dailyAsset);
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object add(@RequestBody DailyAsset dailyAsset) {
        if (this.dailyAssetsService.add(dailyAsset) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.GET})
    @ApiOperation("删除")
    public Object delete(Integer id) {
        if (this.dailyAssetsService.deleteById(id) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改")
    public Object update(@RequestBody DailyAsset dailyAsset) {
        if (this.dailyAssetsService.update(dailyAsset) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/findbydailyprojectId"}, method = {RequestMethod.GET})
    @ApiOperation("按照日常资产项目主键查询")
    public Object findBydailyProjectId(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam Integer dailyProjectId, @RequestParam(required = false) String category, @RequestParam(required = false) String basicsName, @RequestParam(required = false) Integer assetsClassificationId) {
        return this.dailyAssetsService.findBydailyProjectId(pageNum, pageSize, dailyProjectId, category, basicsName, assetsClassificationId);
    }

    @RequestMapping(value = {"/updateStartProvisionDate"}, method = {RequestMethod.POST})
    @ApiImplicitParams({@ApiImplicitParam(name = "startProvisionDate", value = "折旧开始日期", required = true, paramType = "query"), @ApiImplicitParam(name = "id", value = "项目主键", required = true, paramType = "query")})
    @ApiOperation("修改开始计提折旧日期")
    public Object updateStartProvisionDate(@RequestBody JSONObject json) {
        System.out.println(json);
        String startProvisionDate = json.getString("startProvisionDate");
        String[] idNum = json.getString("id").split(",");
        int count2 = 0;
        for (String id : idNum) {
            if (this.dailyAssetsService.findByBuildNum(Integer.valueOf(Integer.parseInt(id))).intValue() == 0) {
                return new CommonResult().validateFailed("当前项目无资产，请录入资产");
            }
            if (this.dailyProjectService.updateSPD(startProvisionDate, null, Integer.valueOf(Integer.parseInt(id))) == 0) {
                return new CommonResult().validateFailed("修改项目信息失败");
            }
            count2 = this.dailyAssetsService.updateStartProvisionDate(startProvisionDate, Integer.valueOf(Integer.parseInt(id))).intValue();
        }
        if (count2 > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }
}